import 'package:flutter/material.dart';
import 'package:ruitmentapp/core/extension/int_extension.dart';
import 'package:ruitmentapp/personnel/model/zj_home_model.dart';
import 'package:ruitmentapp/core/shared/size_fit.dart';
import 'package:ruitmentapp/personnel/model/zj_job_details_model.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

final cardRadius = 5.px;

class ZJHomeContentDutyStationCard extends StatelessWidget {

  final ZJJobDetailsModel _detailsModel;
  ZJHomeContentDutyStationCard(this._detailsModel);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: buildTitleCard(context),
    );
  }

  Widget buildTitleCard(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(left: 20.px, right: 20.px, bottom: 10.px),
      elevation: 0.0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius)),
      child: Column(
        children: <Widget>[
          buildPushTitleInfo(context),
          buildLineInfo(),
          buildOperationInfo(context),
          buildBasicInfo(context),
        ],
      ),
    );
  }

  Widget buildLineInfo() {
    return SizedBox(
        width: ZJSizeFit.screenWidth - 70.px,
        height: 1.px,
        child: Container(
          color: const Color(0xFFF3F5F7),
        )
    );
  }

  Widget buildPushTitleInfo(BuildContext context) {
    return Row(
      children: const [
        Expanded(child:
        Padding(
          padding: EdgeInsets.only(top: 10, left: 15, right: 15,bottom: 10),
          child: Text('工作地点',
              textAlign:TextAlign.left,
              style: TextStyle(
                  color: Color(0xFF3F4756),
                  fontSize: 16,
                  fontWeight: FontWeight.bold)
          ),
        ),
        ),
      ],
    );
  }

  Widget buildBasicInfo(BuildContext context) {

    String title = '${_detailsModel.publishDetail.cityName}${_detailsModel.publishDetail.countyName}${_detailsModel.publishDetail.officeAddress}${_detailsModel.publishDetail.addr}';
    return Container(
      color: Colors.white,
      width: MediaQuery.of(context).size.width - 70,
      height: 40,
      margin: const EdgeInsets.only(top: 5),
      child: SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        scrollDirection: Axis.horizontal,
        child: Center(
          child: Row(
            children: [
              GestureDetector(
                child: Card(
                  elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
                  color: const Color(0xFFF3F5F7),//设置颜色，数字为颜色饱和度
                  shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.0))),
                  child: Container(
                      padding: const EdgeInsets.only(left: 10, top: 3, bottom: 3, right: 10),
                      child: const Text('复制地址', style: TextStyle(color: Color(0xFF77809E),fontSize: 12))
                  ),
                ),
                onTap: ()  async {
                  Clipboard.setData(ClipboardData(text: title));
                  ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
                  print('data content ${data.text}'); //  data content 复制的内容
                  Fluttertoast.showToast(
                      msg: "复制成功",
                      toastLength: Toast.LENGTH_SHORT,
                      gravity: ToastGravity.CENTER,
                      // timeInSecForIos: 1,
                      backgroundColor: Colors.black,
                      textColor: Colors.white,
                  );
                },
              )
            ],
          ),
        ),
      ),
    );
  }

  Widget buildOperationInfo(BuildContext context) {

    String title = '${_detailsModel.publishDetail.cityName}${_detailsModel.publishDetail.countyName}${_detailsModel.publishDetail.officeAddress}${_detailsModel.publishDetail.addr}';
    return Row(
        children: <Widget>[
          Expanded(child:
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Padding(
                  padding: const EdgeInsets.only(left: 15,top:10,right: 15),
                  child: Text(title,
                      style: const TextStyle(color: Color(0xFF77809E), fontSize: 13)),
                ),
              ],
            )
          ),
        ]
    );
  }
}